package ca.ericslandry.client.mvp.presenter;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.place.Place;
import net.customware.gwt.presenter.client.place.PlaceRequest;
import ca.ericslandry.client.resource.MyConstants;
import ca.ericslandry.shared.domain.Target;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.inject.Inject;

public class PeoplePresenter extends BasePresenter<PeoplePresenter.Display> {
	public interface Display extends BasePresenter.BaseDisplay {
	}

	private ContentPresenter contentPresenter;
	public static final Place PLACE = new Place("people");

	@Inject
	public PeoplePresenter(final Display display, final EventBus eventBus, ContentPresenter contentPresenter) {
		super(display, eventBus);
		this.contentPresenter = contentPresenter;
		bind();
	}

	@Override
	protected void onBind() {
		Log.debug("onBind: people");
	}

	public void showPeopleContent() {
		contentPresenter.getDisplay().setContent(display.asWidget());
	}

	@Override
	public Place getPlace() {
		return PLACE;
	}

	@Override
	protected void onPlaceRequest(PlaceRequest placeReq) {
		String action = placeReq.getParameter(ACTION, null);
		if (BROWSE.equalsIgnoreCase(action)) {
			Log.info("onPlaceRequest: show people around me");
			// TODO: implement
		} else if (SEARCH.equalsIgnoreCase(action)) {
			Log.info("onPlaceRequest: find people");
			// TODO: implement
		} else if (CREATE.equalsIgnoreCase(action)) {
			Log.info("onPlaceRequest: add person");
			// TODO: implement
		} else if (RATING.equalsIgnoreCase(action)) {
			Log.info("onPlaceRequest: show people rating");
			// TODO: implement
		} else if (USER.equalsIgnoreCase(action)) {
			Log.info("onPlaceRequest: show civic minded users");
			// TODO: implement
		}
	}

	public static PlaceRequest getDefaultPlaceRequest() {
		return new PlaceRequest(PeoplePresenter.PLACE).with(ACTION, BROWSE);
	}

	public static Hyperlink getLinkPeopleAroundMe() {
		PlaceRequest placeReq = new PlaceRequest(PeoplePresenter.PLACE).with(ACTION, BROWSE);
		return new Hyperlink(MyConstants.INSTANCE.peopleAroundMe(), placeReq.toString());
	}

	public static Hyperlink getLinkFindPeople() {
		PlaceRequest placeReq = new PlaceRequest(PeoplePresenter.PLACE).with(ACTION, SEARCH);
		return new Hyperlink(MyConstants.INSTANCE.findPeople(), placeReq.toString());
	}

	public static Hyperlink getLinkAddPerson() {
		PlaceRequest placeReq = new PlaceRequest(PeoplePresenter.PLACE).with(ACTION, CREATE);
		return new Hyperlink(MyConstants.INSTANCE.addPerson(), placeReq.toString());
	}

	public static Hyperlink getLinkPeopleRating() {
		PlaceRequest placeReq = new PlaceRequest(PeoplePresenter.PLACE).with(ACTION, RATING);
		return new Hyperlink(MyConstants.INSTANCE.rating(), placeReq.toString());
	}

	public static Hyperlink getLinkCivicUsers() {
		PlaceRequest placeReq = new PlaceRequest(PeoplePresenter.PLACE).with(ACTION, USER);
		return new Hyperlink(MyConstants.INSTANCE.civicUsers(), placeReq.toString());
	}

	public static Hyperlink getLinkViewTarget(Target target) {
		PlaceRequest placeReq = new PlaceRequest(PLACE).with(ACTION, VIEW).with(ID, String.valueOf(target.getId()));
		return new Hyperlink(target.getName(), placeReq.toString());
	}
}
